using System;
using System.Collections.Generic;
using System.Text;

namespace WOWEquipOptimizer.Paladin
{
    class Holy : Healer
    {
        public Holy()
            : base()
        {
            AllowShield = true;
            m_Base = new List<Attribute>();
            m_Base.Add(new Attribute(AttributeName.Health, 3200));
            m_Base.Add(new Attribute(AttributeName.Stamina, 118));
            m_Base.Add(new Attribute(AttributeName.Mana, 2673));
            m_Base.Add(new Attribute(AttributeName.Intellect, 87));
            m_Base.Add(new Attribute(AttributeName.Spirit, 88));
            m_Base.Add(new Attribute(AttributeName.CritSpellRating, 3.3f * CritSpellRating));
            // talents
            m_Base.Add(new Attribute(AttributeName.CritRating, 5 * CritRating));          
            foreach (Attribute attr in m_Base)
            {
                handleAttribute(attr);
            }
            GoodAttributes.Add(AttributeName.CritSpellRating);
        }
        // mana, int, spirit, +heal, crit,spellhaste, mp5,health
        public override float evaluateTF()
        {
            float runtime = 600;
            float time = runtime;
            float HL4 = 35 / 70f;
            float HL4cost = 190;
            float HL4heal = 333;
            float spellcrit = m_Equip[AttributeName.CritSpellRating] / CritSpellRating;
            float manaregic = m_Equip[AttributeName.MP5] / 5f;
            float spellhaste = m_Equip[AttributeName.HasteSpellRating] / HasteSpellRating;
            float bol = 580;
            float manaregooc = manaregic + (m_Equip[AttributeName.Spirit] / 5 + 15) / 2;
            float HL4crit = (spellcrit + 6) / 100f;
            float HL4casttime = 2.0f / (1 + spellhaste / 100f);
            float HL4mana = Math.Max(HL4cost * (1 - HL4crit * 0.6f) - manaregic * HL4casttime, 1);
            if (this.SpecialValues.Contains("13597983"))
            {
                HL4mana -= 27;
            }
            HL4mana = Math.Max(HL4mana, 1);
            if (this.SpecialValues.Contains("28405534"))
            {
                bol += 105;
            }
            float count = (float)Math.Floor(m_Equip[AttributeName.Mana] / HL4mana);
            float castuseratio = (manaregooc * HL4casttime ) / HL4mana;
            time -= count * HL4casttime + Math.Max(5 * castuseratio, 5);
            time = Math.Max(time, 0);
            float regtime = 0;
            if(time > 0)
            {
                regtime = time / (castuseratio + 1);
                regtime = Math.Min(regtime, 0.3f * runtime);
                time -= regtime;
            }
            count += (float)Math.Floor((regtime * manaregooc) / HL4mana);
            count = Math.Min(count, (runtime - regtime) / HL4casttime);
            float HealHL4 = 1.12f * count * (HL4heal + bol + m_Equip[AttributeName.Healing] * HL4 * (5 / 7f)); // no healcrits
            return CondFactor * HealHL4 / runtime;
        }
        // mana, int, spirit, +heal, crit,spellhaste, mp5,health
        public override void handleAttribute(Attribute attr)
        {
            switch (attr.Type)
            {
                case AttributeName.Intellect:
                    m_Equip[AttributeName.Mana] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) * 1.1f * 15;
                    m_Equip[AttributeName.Intellect] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) * 1.1f;
                    m_Equip[AttributeName.Healing] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) * 1.1f * 0.35f;
                    m_Equip[AttributeName.CritSpellRating] += (attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) / 80) * 1.1f * CritSpellRating;
                    break;
                case AttributeName.SpellDamage:
                case AttributeName.Healing:
                    m_Equip[AttributeName.Healing] += attr.Value;
                    break;
                default:
                    base.handleAttribute(attr);
                    break;
            }
        }
        public override List<Item> filterEquip(List<Item> input)
        {
            input = base.filterEquip(input);
            List<Item> retval = new List<Item>();
            foreach (Item item in input)
            {
                if ((item.AllowableClasses & CharacterClass.Paladin) == 0) continue;
                if (item.GetType() == typeof(Weapon))
                {
                    Weapon weapon = (Weapon)item;
                    if (weapon.WeaponSlot == WeaponSlot.Ranged)
                    {
                        if (weapon.Type != WeaponType.Libram) continue;
                    }
                    if (weapon.Type == WeaponType.Dagger) continue;
                    if (weapon.TwoHand && weapon.Type == WeaponType.Staff) continue;
                }
                else if (item.GetType() == typeof(Armor))
                {
                    Armor armor = (Armor)item;
                    if ((armor.Type & (ArmorProficiency.Plate | ArmorProficiency.Shield)) == 0) continue;
                }
                if (SetBlacklist.Contains(item.Set.Name)) continue;
                if (ItemBlacklist.Contains(item.Name)) continue;
                retval.Add(item);
            }
            return handleWhiteList(retval);
        }
        public override bool evaluateBuild(int[] build)
        {
            if (build[0] >= 50)
            {
                return true;
            }
            else return false;
        }
    }
}
